<template>
<el-card class="el-card">
  <el-tooltip class="item" effect="dark" content="刷新" placement="top">
    <el-button circle icon="Refresh" @click="update" />
  </el-tooltip>
  <el-table
    :data="ScoreRuleList"
    border
    style="
      width: 100%;
      margin: 20px 0px;
      border-radius: 8px;
      box-shadow: 5px 5px 10px rgba(64, 158, 255, 0.5);
    "
    :header-cell-style="{
      background: '#337ecc !important',
      color: '#ffffff',
      border: 'none !important',
      textAlign: 'center',
    }"
  >
    <el-table-column prop="name" label="员工" width="100"></el-table-column>
    <el-table-column
      prop="checkState"
      label="是否查看本月绩效"
      width="200"
    >
    <template #default="scope">{{scope.row.checkState==0?"否":"是"}}
    </template>
    </el-table-column>
    <el-table-column
      prop="checkCount"
      label="查看绩效次数"
      width="220"
    ></el-table-column>
    <el-table-column prop="updateTime" label="首次查看时间">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.createTime }}</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="updateTime" label="最后查看时间">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.updateTime }}</span>
        </div>
      </template>
    </el-table-column>
  </el-table>
  <pagination
    class="pagination"
    v-show="ScoreListPage.total > 0"
    :total="ScoreListPage.total"
    v-model:page="searchForm.page"
    v-model:limit="ScoreListPage.size"
    @pagination="handlePagination"
  />
  </el-card>
</template>
<script setup>
import {
  ref,
  onMounted,
  onBeforeMount,
  reactive,
  defineEmits,
  watch,
} from "vue";
import { getNowPage } from "@/api/empCheckState";
import { ElMessage } from "element-plus";

const searchForm = ref({
  page: 1,
  page_size: 10,
});
const ScoreListPage = ref([]);
const ScoreRuleList = ref([]);
onBeforeMount(() => {
  getNowPage(searchForm.value).then((data) => {
    ScoreListPage.value = data.data;
    ScoreRuleList.value = data.data.records;
  });
});
watch(
  ScoreRuleList,
  (newVal) => {
  },
  { deep: true }
);

const handlePagination = (value) => {
  getNowPage(searchForm.value).then((data) => {
    ScoreListPage.value = data.data;
    ScoreRuleList.value = data.data.records;
  });
};

let select = reactive();
const DialogVisible = ref(false);
const handleEdit = (index, row) => {
  DialogVisible.value = true;
  select = row;
};

const update = () => {
  getNowPage(searchForm.value).then((data) => {
    if (data.code == 200) {
      ElMessage({
        message: "更新成功",
        type: "success",
      });
      ScoreListPage.value = data.data;
      ScoreRuleList.value = data.data.records;
    } else {
      ElMessage.error("更新失败");
    }
  });
};
</script>

<style lang="scss" scoped>
.el-card {
  border-radius: 10px;
}
.title1 {
  color: rgb(64, 158, 255);
  width: 300px;
  height: 45px;
  font-size: 25px;
  background: rgba(64, 158, 255, 0.4);
  text-align: center;
  border-radius: 10px;
  margin: 10px auto 10px;
  line-height: 45px;
  border-top: #409eff 2px solid;
  border-bottom: #409eff 2px solid;
  box-shadow: 5px 5px 10px rgba(64, 158, 255, 0.5);
}
.pagination {
  margin: 20px 50px;
  display: flex;
  justify-content: end;
}
</style>